package cn.wangzg.themedemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    int id = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
            id = savedInstanceState.getInt("id");
        }
        switch (id) {
            case 0:
                setTheme(R.style.ThemeDemo);
                break;
            case 1:
                setTheme(R.style.red);
                break;
            case 2:
                setTheme(R.style.green);
                break;

        }
        setContentView(R.layout.activity_main);
    }

    public void changeTheme(View view) {
        switch (view.getId()) {
            case R.id.button:
                id = 1;
                break;
            case R.id.button2:
                id = 2;
                break;
        }
        recreate();
    }

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        outState.putInt("id", id);
        super.onSaveInstanceState(outState);
    }
}